﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.BLL;
using YouHP.Utility;
using YouHP.Model;
using System.Text.RegularExpressions;
using System.Web;

namespace YouHP.Pages.Profile
{
    public class Log : YouHP.Pages.Profile.ProfileBasePage
    {
        public override void InitPage()
        {
            base.InitPage();
            this.PageKey = PageKeys.Profile_Log;
        }

        protected override void ShowPage()
        {
            base.ShowPage();
            if (this.ErrorCount > 0) return;

            HandleCommon();
            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected LogTopicInfo logTopicData;
        protected List<LogCommentInfo> ReplyDataList;
        protected string[] tagArrSplit = null; 
        protected int PageIndex = 1;
        protected int DataCount;
        protected int PageCount;
        protected string PagingString;
        
        protected void HandleCommon()
        {
            this.SetTitle("日志");
            this.AddLocation("查看日志", "");
            this.AddScriptSrc("/support/Alpha/Js/mootools.js");
            this.AddLinkCss("/support/alpha/css/log.css");
        }

        protected void HandlePost()
        {
        }

        protected void HandleGet()
        {
            int lid = RequestTools.GetQueryInt("lid",0);
            if (lid <= 0)
            {
                this.AddErrLine("无效的lid ");
                return;
            }
            logTopicData = LogTopicBLL.Instance.GetLogTopicInfo(lid);
            if(logTopicData.Id <= 0)
            {
                this.AddErrLine("该日志不存在或已经被删除");
                return;
            }

            // 更新日志主题的点击次数
            LogTopicBLL.Instance.UpdateLogTopicHits(logTopicData.Id);

            ReplyDataList = LogCommentBLL.Instance.GetLogCommentList(5, PageIndex, lid, out DataCount);

            if (logTopicData.Tags != "")
            {
                tagArrSplit = Regex.Split(logTopicData.Tags, "\\s+");
            }
            
        }
    }
}